/**
 * 
 */
package com.demo2do.fms.admin.entity.search.data;

import java.util.Map;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;

/**
 * @author Chang Liu
 *
 */
public class WarehouseSearch implements QueryBuilder {
	
	/** 仓库名称 */
	private String facilityName;
	
	/** 装载地名称 */
	private String loadPlaceName;
	
	private QueryFilter filter;
	
	private QueryOrder order;

	/**
	 * 
	 */
	public WarehouseSearch() {
		order = new QueryOrder();
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
	 */
	public QueryFilter getPreparedFilter(boolean refresh) {
		
		if(filter == null || refresh){
			filter = new QueryFilter().addLike("name", facilityName)
					                  .addLike("loadPlaceName", loadPlaceName);
		}
		
		return filter;
		
	}

	/*
	 * (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
	 */
	public QueryOrder getOrder() {
		return order;
	}

	/*
	 * (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
	 */
	public String buildSentenceTemplate() {
		String sentence = "FROM Warehouse WHERE disabled = false" + getPreparedFilter(false).clauseSentence() + order.sentence();
		return sentence;
	}

	/*
	 * (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
	 */
	public Map<String, Object> buildParameters() {
		return getPreparedFilter(false).parameters();
	}

	/**
	 * 
	 * @return
	 */
	public QueryFilter getFilter(){
		return getPreparedFilter(false);
	}

    /**
     * @return the facilityName
     */
    public String getFacilityName() {
        return facilityName;
    }

    /**
     * @return
     */
    public String getLoadPlaceName() {
		return loadPlaceName;
	}

    /**
     * @param facilityName the facilityName to set
     */
    public void setFacilityName(String facilityName) {
        this.facilityName = facilityName;
    }

    /**
     * @param loadPlaceName
     */
    public void setLoadPlaceName(String loadPlaceName) {
		this.loadPlaceName = loadPlaceName;
	}
	
}
